#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e9;
int main(){
	int T;
	cin>>T;
	while(T--) {
		string  a,b;
		cin>> a;
		cin>> b;
		int l  =  0;
		int r  =  0;
		int sa=a.size();
		int sb=b.size();
		
		int ltl=0;
		int ltr=0;
		char last=a[0];
		bool f = true;
		for(int i =  0;i < sa; i++){
			ltl=l;
			ltr=r;
			while(last==a[l] && l<sa)l++;
			while(b[r]==last && r<sb)r++;
			i=l;
			last=a[i];
			i--;
			if((l-ltl+1)*2<=(r-ltr+1)||(l-ltl+1)>(r-ltr+1)){
				f=false;S
				break;
			}
		}
		
		if(f&&r==sb) {
			cout<<"YES\n";
		}
		else cout<<"NO\n";
	}
}
